/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Telas;

import ClassesExtras.ButtonTabComponent;
import Conexao.ConexaoBanco;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Marcos
 */
public class Fr_Principal extends javax.swing.JFrame {

    public Connection conexao;
    public static String usuario;

    /**
     * Creates new form Fr_Principal
     */
    public Fr_Principal() throws SQLException {
        initComponents();
        this.conexao = ConexaoBanco.getConexao();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPanePrincipal = new javax.swing.JTabbedPane();
        jPanelUsuario = new javax.swing.JPanel();
        jButtonLogoff = new javax.swing.JButton();
        jLabelUsuario = new javax.swing.JLabel();
        jLabelNomUsuario = new javax.swing.JLabel();
        jPanelLogin = new javax.swing.JPanel();
        jTextFieldLogin = new javax.swing.JTextField();
        jPasswordFieldSenha = new javax.swing.JPasswordField();
        jButtonCancelar = new javax.swing.JButton();
        jButtonEntrar = new javax.swing.JButton();
        jLabelSenha = new javax.swing.JLabel();
        jLabelLogin = new javax.swing.JLabel();
        jLabelCamposObrigatorios = new javax.swing.JLabel();
        jMenuBarFrPrincipal = new javax.swing.JMenuBar();
        jMenuCadastros = new javax.swing.JMenu();
        jMenuItemCadastroPessoa = new javax.swing.JMenuItem();
        jMenuItemCadastroAgendamentoSecretaria = new javax.swing.JMenuItem();
        jMenuItemCadastroCidade = new javax.swing.JMenuItem();
        jMenuItemCadastroUsuario = new javax.swing.JMenuItem();
        jMenuItemCadstroAgendamentoMedico = new javax.swing.JMenuItem();
        jMenuItemAcesso = new javax.swing.JMenuItem();
        jMenuItemCadastroPlanoSaude = new javax.swing.JMenuItem();
        jMenuItemCadastroTempoConsulta = new javax.swing.JMenuItem();
        jMenuItemCadastroPaciente = new javax.swing.JMenuItem();
        jMenuConsultas = new javax.swing.JMenu();
        jMenuItemConsultaPessoa = new javax.swing.JMenuItem();
        jMenuItemConsultaAgendamento = new javax.swing.JMenuItem();
        jMenuItemConsultaCidade = new javax.swing.JMenuItem();
        jMenuRelatorios = new javax.swing.JMenu();
        jMenuItemRelatorioAgendamento = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema");
        setFocusTraversalPolicyProvider(true);
        setIconImages(null);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jTabbedPanePrincipal.setBorder(null);

        jPanelUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButtonLogoff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Logoff.png"))); // NOI18N
        jButtonLogoff.setMnemonic('L');
        jButtonLogoff.setText("Logoff");
        jButtonLogoff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLogoffActionPerformed(evt);
            }
        });

        jLabelUsuario.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabelUsuario.setText("Usuário:");

        jLabelNomUsuario.setFont(new java.awt.Font("sansserif", 2, 14)); // NOI18N

        javax.swing.GroupLayout jPanelUsuarioLayout = new javax.swing.GroupLayout(jPanelUsuario);
        jPanelUsuario.setLayout(jPanelUsuarioLayout);
        jPanelUsuarioLayout.setHorizontalGroup(
            jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelUsuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelNomUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 465, Short.MAX_VALUE)
                .addComponent(jButtonLogoff)
                .addContainerGap())
        );
        jPanelUsuarioLayout.setVerticalGroup(
            jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelUsuarioLayout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNomUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonLogoff)
                        .addComponent(jLabelUsuario)))
                .addContainerGap())
        );

        jPanelLogin.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jTextFieldLogin.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldLoginFocusLost(evt);
            }
        });

        jPasswordFieldSenha.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jPasswordFieldSenhaFocusLost(evt);
            }
        });

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Cancelar.png"))); // NOI18N
        jButtonCancelar.setMnemonic('c');
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jButtonEntrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Ok.png"))); // NOI18N
        jButtonEntrar.setMnemonic('e');
        jButtonEntrar.setText("Entrar");
        jButtonEntrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEntrarActionPerformed(evt);
            }
        });
        jButtonEntrar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonEntrarKeyPressed(evt);
            }
        });

        jLabelSenha.setText("*Senha:");

        jLabelLogin.setText("*Login:");

        jLabelCamposObrigatorios.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabelCamposObrigatorios.setText("* Campos obrigatórios a serem preenchidos");

        javax.swing.GroupLayout jPanelLoginLayout = new javax.swing.GroupLayout(jPanelLogin);
        jPanelLogin.setLayout(jPanelLoginLayout);
        jPanelLoginLayout.setHorizontalGroup(
            jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLoginLayout.createSequentialGroup()
                        .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelSenha)
                            .addComponent(jLabelLogin))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPasswordFieldSenha, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                            .addComponent(jTextFieldLogin))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonEntrar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonCancelar)))
                    .addComponent(jLabelCamposObrigatorios))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelLoginLayout.setVerticalGroup(
            jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLogin)
                    .addComponent(jTextFieldLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEntrar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelSenha)
                    .addComponent(jPasswordFieldSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCancelar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelCamposObrigatorios)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenuCadastros.setText("Cadastros");

        jMenuItemCadastroPessoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Pessoa.png"))); // NOI18N
        jMenuItemCadastroPessoa.setText("Cadastro de Pessoa");
        jMenuItemCadastroPessoa.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                jMenuItemCadastroPessoaMouseDragged(evt);
            }
        });
        jMenuItemCadastroPessoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroPessoaActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroPessoa);

        jMenuItemCadastroAgendamentoSecretaria.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Agendamento.png"))); // NOI18N
        jMenuItemCadastroAgendamentoSecretaria.setText("Cadastro de Agendamento");
        jMenuItemCadastroAgendamentoSecretaria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroAgendamentoSecretariaActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroAgendamentoSecretaria);

        jMenuItemCadastroCidade.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Cidade.png"))); // NOI18N
        jMenuItemCadastroCidade.setText("Cadastro de Cidade");
        jMenuItemCadastroCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroCidadeActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroCidade);

        jMenuItemCadastroUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Usuario.png"))); // NOI18N
        jMenuItemCadastroUsuario.setText("Cadastro de Usuário");
        jMenuItemCadastroUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroUsuarioActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroUsuario);

        jMenuItemCadstroAgendamentoMedico.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Agendamento.png"))); // NOI18N
        jMenuItemCadstroAgendamentoMedico.setText("Cadastro Agendamento");
        jMenuItemCadstroAgendamentoMedico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadstroAgendamentoMedicoActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadstroAgendamentoMedico);

        jMenuItemAcesso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Acesso.png"))); // NOI18N
        jMenuItemAcesso.setText("Acesso");
        jMenuItemAcesso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAcessoActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemAcesso);

        jMenuItemCadastroPlanoSaude.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Plano de Saude.png"))); // NOI18N
        jMenuItemCadastroPlanoSaude.setText("Cadastro Plano de Saúde");
        jMenuItemCadastroPlanoSaude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroPlanoSaudeActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroPlanoSaude);

        jMenuItemCadastroTempoConsulta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Tempo.png"))); // NOI18N
        jMenuItemCadastroTempoConsulta.setText("Cadastro de Tempo de Consulta");
        jMenuItemCadastroTempoConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroTempoConsultaActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroTempoConsulta);

        jMenuItemCadastroPaciente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Pessoa.png"))); // NOI18N
        jMenuItemCadastroPaciente.setText("Cadastro de Paciente");
        jMenuItemCadastroPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCadastroPacienteActionPerformed(evt);
            }
        });
        jMenuCadastros.add(jMenuItemCadastroPaciente);

        jMenuBarFrPrincipal.add(jMenuCadastros);

        jMenuConsultas.setText("Consultas");

        jMenuItemConsultaPessoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Consultar.png"))); // NOI18N
        jMenuItemConsultaPessoa.setText("Consulta de Pessoa");
        jMenuItemConsultaPessoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemConsultaPessoaActionPerformed(evt);
            }
        });
        jMenuConsultas.add(jMenuItemConsultaPessoa);

        jMenuItemConsultaAgendamento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Consultar.png"))); // NOI18N
        jMenuItemConsultaAgendamento.setText("Consulta de Agendamento");
        jMenuConsultas.add(jMenuItemConsultaAgendamento);

        jMenuItemConsultaCidade.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Consultar.png"))); // NOI18N
        jMenuItemConsultaCidade.setText("Consulta de Cidade");
        jMenuItemConsultaCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemConsultaCidadeActionPerformed(evt);
            }
        });
        jMenuConsultas.add(jMenuItemConsultaCidade);

        jMenuBarFrPrincipal.add(jMenuConsultas);

        jMenuRelatorios.setText("Relatórios");

        jMenuItemRelatorioAgendamento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Relatorio.png"))); // NOI18N
        jMenuItemRelatorioAgendamento.setText("Relatório de Agendamento");
        jMenuItemRelatorioAgendamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRelatorioAgendamentoActionPerformed(evt);
            }
        });
        jMenuRelatorios.add(jMenuItemRelatorioAgendamento);

        jMenuBarFrPrincipal.add(jMenuRelatorios);

        setJMenuBar(jMenuBarFrPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPanePrincipal)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPanePrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        Dimension tela = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(700, 460);
        setLocation((tela.width - this.getSize().width) / 2, (tela.height - this.getSize().height) / 2);
        setExtendedState(MAXIMIZED_BOTH);
        jMenuBarFrPrincipal.setVisible(false);
        jTextFieldLogin.grabFocus();
        jPanelUsuario.setVisible(false);

        /*
        HashSet conj = new HashSet(jPanelLogin.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
        conj.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
        jPanelLogin.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, conj);
        */
    }//GEN-LAST:event_formWindowOpened

    private void jMenuItemCadastroPessoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroPessoaActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        jTabbedPanePrincipal.grabFocus();
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Pessoa");
        panel.add(new Jp_CadastroPessoa());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        Dimension dimensao = new Dimension(300, 90);
        panel.setSize(dimensao);

        int i = jTabbedPanePrincipal.getSelectedIndex(); //Botão fechar na aba
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroPessoaActionPerformed

    private void jMenuItemCadastroAgendamentoSecretariaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroAgendamentoSecretariaActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Agendamento");
        try {
            panel.add(new Jp_CadastroAgendamentoSecretaria());
        } catch (SQLException ex) {
            Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroAgendamentoSecretariaActionPerformed

    private void jMenuItemCadastroPessoaMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItemCadastroPessoaMouseDragged
        //jMenuItemCadastroPaciente.setLocation(jMenuItemCadastroPaciente.getX() + evt.getX(), jMenuItemCadastroPaciente.getY() + evt.getY());
    }//GEN-LAST:event_jMenuItemCadastroPessoaMouseDragged

    private void jMenuItemConsultaPessoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemConsultaPessoaActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Consulta de Pessoa");
        panel.add(new Jp_ConsultaPessoa());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemConsultaPessoaActionPerformed

    private void jMenuItemCadastroCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroCidadeActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Cidade");
        try {
            panel.add(new Jp_CadastroCidade());
        } catch (SQLException ex) {
            Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroCidadeActionPerformed

    private void jMenuItemConsultaCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemConsultaCidadeActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Consulta de Cidade");
        panel.add(new Jp_ConsultaCidade());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemConsultaCidadeActionPerformed

    private void jButtonEntrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEntrarActionPerformed
        senha_usuario();
    }//GEN-LAST:event_jButtonEntrarActionPerformed

    private void jButtonLogoffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLogoffActionPerformed
        jPanelUsuario.setVisible(false);
        jPanelLogin.setVisible(true);
        jMenuBarFrPrincipal.setVisible(false);
        jTabbedPanePrincipal.removeAll();
        jTextFieldLogin.grabFocus();
        jTextFieldLogin.setText(null);
        jPasswordFieldSenha.setText(null);
    }//GEN-LAST:event_jButtonLogoffActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jMenuItemCadastroUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroUsuarioActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Usuário");
        try {
            panel.add(new Jp_CadastroUsuario());
        } catch (SQLException ex) {
            Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroUsuarioActionPerformed

    private void jButtonEntrarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonEntrarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            senha_usuario();
        }
    }//GEN-LAST:event_jButtonEntrarKeyPressed

    private void jMenuItemRelatorioAgendamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRelatorioAgendamentoActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Relatório de Agendamento");
        panel.add(new Jp_RelatorioAgendamento());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemRelatorioAgendamentoActionPerformed

    private void jMenuItemCadstroAgendamentoMedicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadstroAgendamentoMedicoActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Agendamento");
        panel.add(new Jp_CadastroAgendamentoMedico());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadstroAgendamentoMedicoActionPerformed

    private void jTextFieldLoginFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldLoginFocusLost
        jPasswordFieldSenha.grabFocus();
    }//GEN-LAST:event_jTextFieldLoginFocusLost

    private void jPasswordFieldSenhaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPasswordFieldSenhaFocusLost
        jButtonEntrar.grabFocus();
    }//GEN-LAST:event_jPasswordFieldSenhaFocusLost

    private void jMenuItemAcessoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAcessoActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Acesso");
        panel.add(new Jp_Acesso());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemAcessoActionPerformed

    private void jMenuItemCadastroPlanoSaudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroPlanoSaudeActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro Plano de Saúde");
        try {
            panel.add(new Jp_CadastroPlanoSaude());
        } catch (SQLException ex) {
            Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroPlanoSaudeActionPerformed

    private void jMenuItemCadastroTempoConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroTempoConsultaActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro Tempo de Consulta");
        panel.add(new Jp_CadastroTempoConsulta());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroTempoConsultaActionPerformed

    private void jMenuItemCadastroPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCadastroPacienteActionPerformed
        jTabbedPanePrincipal.setVisible(true);
        JPanel panel = new JPanel();
        panel.setName("Cadastro de Paciente");
        panel.add(new Jp_CadastroPaciente());
        jTabbedPanePrincipal.add(panel);
        jTabbedPanePrincipal.setSelectedComponent(panel);

        int i = jTabbedPanePrincipal.getSelectedIndex();
        jTabbedPanePrincipal.setTabComponentAt(i, new ButtonTabComponent(jTabbedPanePrincipal));
    }//GEN-LAST:event_jMenuItemCadastroPacienteActionPerformed

    /**
     * @param args the command line argumentsS
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feamael */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;


                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Fr_Principal.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fr_Principal.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fr_Principal.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fr_Principal.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new Fr_Principal().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonEntrar;
    private javax.swing.JButton jButtonLogoff;
    private javax.swing.JLabel jLabelCamposObrigatorios;
    private javax.swing.JLabel jLabelLogin;
    private javax.swing.JLabel jLabelNomUsuario;
    private javax.swing.JLabel jLabelSenha;
    private javax.swing.JLabel jLabelUsuario;
    public javax.swing.JMenuBar jMenuBarFrPrincipal;
    private javax.swing.JMenu jMenuCadastros;
    private javax.swing.JMenu jMenuConsultas;
    private javax.swing.JMenuItem jMenuItemAcesso;
    private javax.swing.JMenuItem jMenuItemCadastroAgendamentoSecretaria;
    private javax.swing.JMenuItem jMenuItemCadastroCidade;
    private javax.swing.JMenuItem jMenuItemCadastroPaciente;
    private javax.swing.JMenuItem jMenuItemCadastroPessoa;
    private javax.swing.JMenuItem jMenuItemCadastroPlanoSaude;
    private javax.swing.JMenuItem jMenuItemCadastroTempoConsulta;
    private javax.swing.JMenuItem jMenuItemCadastroUsuario;
    private javax.swing.JMenuItem jMenuItemCadstroAgendamentoMedico;
    private javax.swing.JMenuItem jMenuItemConsultaAgendamento;
    private javax.swing.JMenuItem jMenuItemConsultaCidade;
    private javax.swing.JMenuItem jMenuItemConsultaPessoa;
    private javax.swing.JMenuItem jMenuItemRelatorioAgendamento;
    private javax.swing.JMenu jMenuRelatorios;
    private javax.swing.JPanel jPanelLogin;
    private javax.swing.JPanel jPanelUsuario;
    private javax.swing.JPasswordField jPasswordFieldSenha;
    public javax.swing.JTabbedPane jTabbedPanePrincipal;
    private javax.swing.JTextField jTextFieldLogin;
    // End of variables declaration//GEN-END:variables

    public void senha_usuario() {
        String usuario = jTextFieldLogin.getText();
        //String senha_cifrada = SenhaLogix.cifrarSenhaLogix(usuario, String.valueOf(jPasswordFieldSenha.getPassword()));
        String senha = jPasswordFieldSenha.getText();
        String sql = "select usuario from login where usuario = ? and senha = ? and status = 'A'";
        try {
            PreparedStatement stmt = this.conexao.prepareStatement(sql);
            stmt.setString(1, usuario);
            stmt.setString(2, senha);
            ResultSet rs = stmt.executeQuery();

            if (rs.next()) {
                jMenuBarFrPrincipal.setVisible(true);
                //jTabbedPanePrincipal.setVisible(false);
                jPanelUsuario.setVisible(true);
                jPanelLogin.setVisible(false);
                usuario = jTextFieldLogin.getText();
                jLabelNomUsuario.setText(usuario);

            } else {
                JOptionPane.showMessageDialog(null, "Usuário Inativo/Login ou senha Inválido!", "Atenção", JOptionPane.WARNING_MESSAGE);
                jTextFieldLogin.grabFocus();
                jTextFieldLogin.setText("");
                jPasswordFieldSenha.setText("");
                jTextFieldLogin.grabFocus();
            }
        } catch (SQLException ex) {
            Logger.getLogger(Fr_Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}